hysop.tools.henum module

Tool to create enums compatible with C (32 bit signed integers) * EnumFactory

class hysop.tools.henum.EnumFactory[source]

Bases: object

Class with utilities to create enums.

class MetaEnum[source]

Bases: type

static create(name, fields, dtype=<class 'numpy.int32'>, base_cls=<class 'object'>)[source]

Create a static enum with corresponding dtype.

Parameters:
  • name (str) – Type name of the enumeration.

  • fields (dict or list) – Dictionary of enum fields as string and corresponding values. If this is a list, the first element will the value 0 and so on.

  • dtype (np.int32, np.int64, np.uint32, np.uint64) – Underlying storage type for enum values. For C compatibility use np.int32. For C++ you can use any of signed or unsigned integer or long integer.

Returns:

An enum class based on input fields and dtype.

Return type:

generated_enum

Examples

fields = {‘X’:0, ‘Y’:1, ‘Z’:42} TestEnum = EnumFactory.create(‘Test’, fields)

X = TestEnum() Y = TestEnum(‘Y’) Z = TestEnum.Z

print(TestEnum.dtype) print(TestEnum.fields()) print(TestEnum[‘X’], TestEnum[‘Y’], TestEnum[‘Z’])

print(TestEnum.rfields()) print(TestEnum[0], TestEnum[1], TestEnum[42]) print() print(TestEnum.X, TestEnum.Y, TestEnum.Z) print(X, Y, Z) print() print(X.__class__.__name__) print(X.value(), X()) print(X.svalue(), str(X)) print(repr(X))

See also

Generate, None